/**
This is the Thrift definition for the Speed Limiter

A download protocol should run the attempt method. The method will block until enough time has gone past that the request amount can be transferred
Preferrably, the amount should be small, so that it returns faster
*/

namespace java hydrap2p.speedlimiter
namespace csharp hydrap2p.speedlimiter

include "service.thrift"
include "download.thrift"

exception InvalidParameter {
	1: string name,
	2: i32 bytesPerSecond,
}

/**
A LoggingListener is an object that receives log events and processes them in some manner
*/
service SpeedLimiter extends service.Service {
	/**
		Blocks until the SpeedManager thinks that the speed is low enough that it can be sent
		
		@param download indicates the direction of the requested transfer
		@param amount is the amount of data to be transferred
	*/
	void attempt(1:download.Source peer, 2:bool download, 3:i32 amount),
	
	/**
		Gets the list of queues that this SpeedLimiter filters transfers into
		
		@return A map of the queue's name to its current limit
	*/
	map<string, i32> getQueues(),
	
	/**
		Sets the new speed limit for the named queue
		Setting it to 0 removes the limit
		
		@throws InvalidParameter if the name does not exist or the bytes per second is negative
	*/
	void setQueueLimit(1:string name, 2:i32 bytesPerSecond) throws (1:InvalidParameter invalid), 
}
